package com.imu.service.impl;

import com.imu.model.Article;
import com.imu.mapper.ArticleMapper;
import com.imu.service.IArticleService;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 文章表 服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2017-05-27
 */
@Service
public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article> implements IArticleService {
	@Autowired
	ArticleMapper articleMapper;
	
	@Override
	public List<Article> indexNews() {
		EntityWrapper<Article> wrapper = new EntityWrapper<Article>();
		wrapper.eq("type", 1).eq("index_flag", 0).eq("delete_flag", 0);
		wrapper.orderBy("update_time");
		wrapper.limit(0, 4);
		return this.selectList(wrapper);
	}

	@Override
	public List<Article> indexZckjs() {
		EntityWrapper<Article> wrapper = new EntityWrapper<Article>();
		wrapper.eq("type", 4).eq("index_flag", 0).eq("delete_flag", 0);
		wrapper.orderBy("update_time");
		wrapper.limit(0, 9);
		return this.selectList(wrapper);
	}

	@Override
	public int zckjsNum() {
		EntityWrapper<Article> wrapper = new EntityWrapper<Article>();
		wrapper.eq("type", 4).eq("delete_flag", 0);
		return this.selectCount(wrapper);
	}

	@Override
	public List<Article> zckjList(int page) {
		EntityWrapper<Article> wrapper = new EntityWrapper<Article>();
		wrapper.eq("type", 4).eq("delete_flag", 0);
		wrapper.orderBy("id");
		wrapper.limit(0+((9)*(page-1)), 9+((9+1)*(page-1)));
		return this.selectList(wrapper);
	}

	@Override
	public Article zckjDetail(int id) {
		EntityWrapper<Article> wrapper = new EntityWrapper<Article>();
		wrapper.eq("type", 4).eq("delete_flag", 0).eq("id", id);
		return this.selectOne(wrapper);
	}
	
}
